import numpy as np
import matplotlib.pyplot as plt

# read the data from problemE.txt
data_a1 = np.loadtxt('./data/problemE_a1.txt')
point_a1 = data_a1[:, 0]
value_a1 = data_a1[:, 1]

data_a2 = np.loadtxt('./data/problemE_a2.txt')
point_a2 = data_a2[:, 0]
value_a2 = data_a2[:, 1]

data_b1 = np.loadtxt('./data/problemE_b1.txt')
point_b1 = data_b1[:, 0]
value_b1 = data_b1[:, 1]

data_b2 = np.loadtxt('./data/problemE_b2.txt')
point_b2 = data_b2[:, 0]
value_b2 = data_b2[:, 1]

# plot the data into curves
plt.plot(point_a1, value_a1, label="specious 1")
plt.plot(point_a2, value_a2, label="specious 2")
plt.title("average weight of larvae")
plt.legend()
plt.savefig("./pic/problemE_average.png")
plt.show()

plt.plot(point_b1, value_b1, label="specious 1")
plt.plot(point_b2, value_b2, label="specious 2")
plt.title("predicted weight of larvae")
plt.legend()
plt.savefig("./pic/problemE_predict.png")
plt.show()
